package com.yiqi.lottery.feature.lottery.view;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.suozhang.framework.component.recyclerview.DividerItemDecoration;
import com.suozhang.framework.entity.bo.PageData;
import com.suozhang.framework.framework.BaseFragment;
import com.suozhang.framework.utils.logger.Logger;
import com.suozhang.framework.widget.EmptyView;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.BaseBo;
import com.yiqi.lottery.entity.bo.CircleBo;
import com.yiqi.lottery.entity.bo.ConfirmLotteryBo;
import com.yiqi.lottery.entity.bo.FoucsBo;
import com.yiqi.lottery.feature.find.contract.CircleContract;
import com.yiqi.lottery.feature.find.dependencies.circle.CirclePresenterModule;
import com.yiqi.lottery.feature.find.dependencies.circle.DaggerCircleComponent;
import com.yiqi.lottery.feature.lottery.data.ConfirmLotteryOpe;
import com.yiqi.lottery.feature.lottery.view.adapter.WinningAdapter;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class WinningColumnFragment extends BaseFragment implements BaseQuickAdapter.OnItemClickListener, CircleContract.View {


    @BindView(R.id.rv_winning)
    RecyclerView mRvWinning;
    private WinningAdapter mAdapter;

    public int type = 3;
    @Inject
    CircleContract.Presenter mPresenter;
    private EmptyView mEmptyView;


    @Override
    public int attachLayoutRes() {
        return R.layout.fragment_winning_column;
    }


    @Override
    protected void initInjector() {
        DaggerCircleComponent.builder().circlePresenterModule(new CirclePresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initAdapter();
    }

    @Override
    protected void initData() {
        mPresenter.doGetCircleList(0, type, 0);
    }

    @Override
    public void onStart() {
        super.onStart();
        Logger.e(this.getClass().getSimpleName() + "------------>onStart()");
        initData();
    }

    @Override
    protected void initEvent() {

    }

    private void initAdapter() {
        mAdapter = new WinningAdapter();
        mEmptyView = new EmptyView(mRvWinning);
        mRvWinning.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRvWinning.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));
        mAdapter.bindToRecyclerView(mRvWinning);
        mAdapter.setOnItemClickListener(this);

    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        startActivity(new Intent(getActivity(), CommonWebActivity.class));
    }


    @Override
    public void showDetailSuccess(FoucsBo foucsBo) {

    }


    @Override
    public void showCircleListSuccess(PageData<CircleBo> circleBoPageData) {
        mAdapter.setNewData(circleBoPageData.getList());
    }

    @Override
    public void showCircleListMoreSuccess(PageData<CircleBo> circleBoPageData) {

    }

    @Override
    public void showCircleMoreErrorMsg(String msg) {

    }

    @Override
    public void showCircleListError(String error) {
        mAdapter.setEmptyView(mEmptyView.getErrorView(error));
        mAdapter.setNewData(null);
    }

    @Override
    public void showCircleListEmpty() {
        mAdapter.setEmptyView(mEmptyView.getEmptyView());
        mAdapter.setNewData(null);
    }

    @Override
    public void showDaiaZanSuccess(String msg) {

    }

    @Override
    public void showDaiaZanError(String msg) {

    }
}
